﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using BusinessObject;
using Entity;
using System.IO;


namespace GreenLife.Admin
{
    public partial class UpdateGreenLifes : System.Web.UI.Page
    {
        DataSet ds;
        GreenLifes gl;
        GreenLifes gl1;
        GreenLifesBO glBO = new GreenLifesBO();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                selectGreenLifesById();
            }
        }

        public void selectGreenLifesById()
        {
            gl = new GreenLifes();
            int id = Int32.Parse(Request.QueryString["id"]);
            gl = glBO.selectGreenLifesById(id);

            txtID.Text = gl.GreenLifesID.ToString();
            txtTitle.Text = gl.GreenLifesTitle.ToString();
            txtQuickTitle.Text = gl.GreenLifesQuickTitle.ToString();
            imgGreenLifes.ImageUrl = gl.GreenLifesImages.ToString();
            txtContent.Text = gl.GreenLifesContents.ToString();
            ddlList.SelectedValue = gl.GreenLifesStatus.ToString();
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            int id = Int32.Parse(Request.QueryString["id"]);
            gl1 = glBO.selectGreenLifesById(id);

            gl = new GreenLifes();
            gl.GreenLifesID = Int32.Parse(txtID.Text);
            gl.GreenLifesTitle = txtTitle.Text;
            gl.GreenLifesQuickTitle = txtQuickTitle.Text;
            if (Path.GetFileName(FileUploadControl.FileName).Equals("") == true)
            {
                gl.GreenLifesImages = gl1.GreenLifesImages.ToString();
            }
            else
            {
                gl.GreenLifesImages = "~/imageUpload/" + Path.GetFileName(FileUploadControl.FileName);
            }
            gl.GreenLifesContents = txtContent.Text;
            gl.GreenLifesStatus = Int32.Parse(ddlList.SelectedValue);
            if (glBO.updateGreenLifes(gl))
            {
                Response.Redirect("GreenLifesShow.aspx");
            }
        }
    }
}